package io.renren.modules.backstage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.exception.Result;
import io.renren.common.exception.StatusCode;
import io.renren.modules.backstage.dao.BorrowerDao;
import io.renren.modules.backstage.entity.BorrowerEntity;
import io.renren.modules.backstage.service.BorrowerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

@Service("borrowerService")
public class BorrowerServiceimpl implements BorrowerService {

    @Resource
    BorrowerDao borrowerDao;



    @Override
    public void save(BorrowerEntity borrowerEntity) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        borrowerDao.insert(borrowerEntity);
    }

    @Override
    public Result getAll(BorrowerEntity borrowerEntity) {

        Page<BorrowerEntity> page = new Page<>(borrowerEntity.getPageNum(),borrowerEntity.getPageSize());
        QueryWrapper<BorrowerEntity> queryWrapper = new QueryWrapper<>();
        if(borrowerEntity.getRepaymentType()!=null && !borrowerEntity.getRepaymentType().equals("")){
            queryWrapper.like("repayment_type",borrowerEntity.getRepaymentType());
        }
        queryWrapper.eq("states",1);
        Page<BorrowerEntity> entityPage =borrowerDao.selectPage(page, queryWrapper);
        return new Result(StatusCode.OK,"贷款数据查询成功",true,entityPage);
    }

    @Override
    public BorrowerEntity getByBorrowId(int borrowId) {
        QueryWrapper<BorrowerEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("borrow_id",borrowId);
        BorrowerEntity borrowerEntity= borrowerDao.selectOne(queryWrapper);
        return borrowerEntity;
    }
}
